<?
define('_VIEW_MODEL_','default');
require_once './init.php';
header("Content-type:text/vnd.wap.wml;charset=utf-8");
$id = intval($id);
$no = intval($auid);
$nid = intval($nid);
$error ="";
if(isset($act)&&$act=="edit"){
	//echo "select title from {$telper}chapter where id=$nid";
	$inf = $db->GetRow("select title from {$telper}chapter where id=$nid");
}else{
$act = "add";
	$inf = "false";
}
if(isset($action)&&$action=="edit"){
	$nd = $db->GetRow("select novelid from {$telper}chapter where id='$nid'");
	$tim = time();
	if(strlen($chaptername) >6 && strlen($chaptername)<=80){
		$db->Execute("update {$telper}chapter set `title`='$chaptername' where id={$nid} ");
		header("Location:noveldetil.php?id={$id}&auid={$no}&nid={$nd[novelid]}");
		exit;
	}else{
		$error = "标题在3-40个汉字之间";
	}
}
if(isset($action)&&$action=="add"){
	$tim = time();
	if(strlen($chaptername) >6 && strlen($chaptername)<=80){
		$nu = $db->GetRow("select count(id) from {$telper}chapter where novelid='$nid'");
		$num = !empty($nu)?$nu['count(id)']:'0';
		$n  = $num+1;
		$db->Execute("insert {$telper}chapter set `novelid`='$nid',`title`='$chaptername',`chapternum`='$n',`wordnum`='0',`created`='$tim',`state`='0'");
		header("Location:noveldetil.php?id={$id}&auid={$no}&nid={$nid}");
		exit;
	}else{
		$error = "标题在3-40个汉字之间";
	}
}
$smartyObj->assign("id",$id);
$smartyObj->assign("auid",$no);
$smartyObj->assign("noid",$nid);
$smartyObj->assign("erro",$error);
$smartyObj->assign("act",$act);
$smartyObj->assign("info",$inf);
$smartyObj->display("addartic.tpl");
?>